package com.lagou.edu.service.impl;

import com.lagou.edu.dao.TokenDao;
import com.lagou.edu.pojo.Token;
import com.lagou.edu.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * Created by Heweipo on 2021/2/15.
 */
@Service
public class TokenServiceImpl implements TokenService {

    @Autowired
    private TokenDao tokenDao;

    @Override
    public Token findOneByToken(String token) {
        Token tk = new Token();
        tk.setToken(token);
        Optional<Token> one = tokenDao.findOne(Example.of(tk));
        return one.orElse(null);
    }

    @Override
    public Token save(Token token) {
        return tokenDao.save(token);
    }
}
